<?php
namespace Tyrone\Model\Game;
use Tyrone\Model\Base;
use Medoo\Medoo;

class LogLogin extends Base
{
    protected $table = 'log_login';


    /**
     * 获取玩家登入登出数量
     * @param int $day 统计日期
     * @return mixed
     */
    public function getLoginInfo($day)
    {
        $start_time = strtotime($day . ' 00:00:00');
        $end_time = strtotime($day . ' 23:59:59');
        return $this->database->select($this->table.'(log)',[
            '[><]role(r)' => ['log.role_id' => 'id'],
        ],[
            'log.role_id(player_id)',
            'r.pf(platform)',
            'r.account(username)',
            'r.zone_id(server_id)',
            'r.lev(level)',
            'r.fc(power)',
            'r.reg_time',
            'day' => Medoo::raw('FROM_UNIXTIME(time, \'%Y-%m-%d\')'),
            'online_time' => Medoo::raw('SUM(CASE WHEN `type` = 1 THEN online_time ELSE 0 END)'),
            'login_num' => Medoo::raw('SUM(CASE WHEN `type` = 0 THEN 1 ELSE 0 END)'),
        ],[
            'log.time[<>]' => [$start_time, $end_time],
            'GROUP'=>'log.role_id',
        ]);



    }

}